<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/4/10 0010
 * Time: 下午 2:19
 */

namespace app\sports_admin\model;


use think\Model;

class WatchMonitoring extends Model
{
    protected $autoWriteTimestamp = true;

    protected $pk = 'id';

    protected $table = 'watch_monitoring';

    protected $hidden = ['update_time'];
    public function getCreateTimeAttr($value)
    {
        return date("Y-m-d H:i:s",$value);
    }
    //获取班级
    public function getClass()
    {
        return $this->belongsTo('class_model','class_id','id')->field('id,grade_id,class_name');
    }
    //获取学生
    public function student()
    {
        return $this->belongsTo('student','student_id','id')->field('id,school_id,stu_name');
    }

    /**
     * @param 获取检测信息
     * $page 第几页
     * $rows 每页显示的条数
     * $sortName 要排序的字段
     * $sortOrder 升序或降序
     * $searchName 要检所的字段
     */
    public static function listInfo($page,$rows,$sortName,$sortOrder)
    {
        $info = self::with('getClass.getGrade,student.school')->page($page)->limit($rows)->order($sortName,$sortOrder)->select();
        $count = self::with('getClass.getGrade,student.school')->count();
        return ['rows'=>$info,'total'=>$count];
    }
}